package com.share.lottery.base;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.UnsupportedEncodingException;

import com.share.lottery.model.User;
import com.share.lottery.model.UserInfo;
import com.share.lottery.view.CustomToast;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.InputFilter;
import android.text.Spanned;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.RelativeLayout;

/**
 * 获取网络数据等的常量保存位置
 * 
 * @author lmj
 * 
 */
public class Constants {
	
	public static final int register = 0;
	
	public static boolean isLoginout = true;
	public static final String BASE_IP = "http://fc.cherry.wilead.com/";
	// 图片的ip
	public static final String PHOTO_ADDR = BASE_IP;
	public static final int PAGE_SIZE = 20; // 分页数据加载的条数
	public static String OID = "a3e12fcd9b998b2e4bb1416b9bd50cb4";
	public static final int login = 1;
	/*************************************** 文档本地图片缓存地址 *******************************************/

	public static String CR_SDCARD = android.os.Environment
			.getExternalStorageDirectory().getAbsolutePath();

	public static final String IMG_CACHE_PATH = CR_SDCARD + "/.lottery_cache";
	public static final String VOICE_BASE_PATH = CR_SDCARD + "/.lottery/Voice";
	public static final String IMG_STORAGE_PATH = CR_SDCARD + "/photo";

	/************************************** 文档BASE接口结束 ************************************************/

	/**
	 * 获取进行中的推荐列表
	 */
	public static final String caibo_rmd_running = BASE_IP
			+ "caibao_rmd/running/";
	/**
	 * 获取已完成的推荐列表
	 */
	public static final String caibo_rmd_finished = BASE_IP
			+ "caibao_rmd/finished/";
	/**
	 * 获取推荐方案统计数据
	 */
	public static final String caibo_rmd_statistics = BASE_IP
			+ "caibao_rmd/statistics/";
	/**
	 * 获取具体方案内容
	 */
	public static final String caibo_rmd_plan = BASE_IP + "caibao_rmd/plan/";
	/**
	 * 获取验证码
	 */
	public static final String caibo_rmd_comment_get = BASE_IP
			+ "api/send/verification_code";
	/**
	 * 评论方案
	 */
	public static final String caibo_rmd_comment_post = BASE_IP
			+ "caibao_rmd/comment/";
	/**
	 * 评价方案
	 */
	public static final String caibo_rmd_evluationn = BASE_IP
			+ "caibao_rmd/evaluation/";
	/**
	 * 选择彩种
	 */
	public static final String caibo_rmd_lottery = BASE_IP
			+ "caibao_rmd/lottery/";

	/**
	 * 获取可订购服务
	 */
	public static final String caibo_rmd_order = BASE_IP + "caibao_rmd/order/";
	/**
	 * 获取服务价格
	 * 
	 */
	public static final String caibo_rmd_order_price = BASE_IP
			+ "caibao_rmd/order/";
	/**
	 * 购买服务
	 */
	public static final String caibo_rmd_order_buy = BASE_IP
			+ "caibao_rmd/order/";

	/*********************** 专家推荐开始 ****************************************/
	/**
	 * 获取进行中的推荐列表
	 */
	public static final String expert_rmd_running = BASE_IP
			+ "/expert_rmd/running/";
	/**
	 * 获取已完成的推荐列表
	 */
	public static final String expert_rmd_finished = BASE_IP
			+ "expert_rmd/finished/";
	/**
	 * 获取推荐方案统计数据
	 */
	public static final String expert_rmd_statistics = BASE_IP
			+ "expert_rmd/statistics/";
	/**
	 * 获取具体方案内容
	 */
	public static final String expert_rmd_plan = BASE_IP + "expert_rmd/plan/";
	/**
	 * 获取方案评论内容
	 */
	public static final String expert_rmd_comment_get = BASE_IP
			+ "expert_rmd/comment/";
	/**
	 * 评论方案
	 */
	public static final String expert_rmd_comment_post = BASE_IP
			+ "expert_rmd/comment/";
	/**
	 * 评价方案
	 */
	public static final String expert_rmd_evluationn = BASE_IP
			+ "expert_rmd/evaluation/";
	/**
	 * 选择专家
	 */
	public static final String expert_select = BASE_IP + "expert_rmd/expert/";

	/**
	 * 获取可订购服务
	 */
	public static final String expert_rmd_order = BASE_IP + "expert_rmd/order/";
	/**
	 * 获取服务价格
	 * 
	 */
	public static final String expert_rmd_order_price = BASE_IP
			+ "expert_rmd/order/";
	/**
	 * 购买服务
	 */
	public static final String expert_rmd_order_buy = BASE_IP
			+ "expert_rmd/order/";
	/**
	 * 获取专家信息
	 */
	public static final String expert_info_get = BASE_IP + "expert_rmd/expert/";
	
	/************开奖公告**************/
	
	/**
	 * 开奖公告列表
	 */
	public static final String bulletin_list =BASE_IP + "bulletin/list/";
	/**
	 * 彩种管理
	 */
    public static final String bulletin_show=BASE_IP +"bulletin/lottshow/";
    /**
     * 彩种排序
     */
    public static final String bulletin_lottsort=BASE_IP +"bulletin/lottsort/";
    /**
     * 开奖号码
     */
    public static String bulletin_number=BASE_IP+"bulletin/number/";
    
   /***************我的彩宝*******************/  
    /**
     * 用户信息
     */
    public static final String caibao_my_userinfo = BASE_IP+"caibao_my/userinfo/";
    /**
     * 获取彩宝价格
     */
    public static final String my_caibo_buycoin = BASE_IP+"caibao_my/buycoin/";
    /**
     * 确定购买单号
     */
	public static final String mycaibo_buy_no = BASE_IP+"caibao_my/buycoin/";
	/**
     * 更新购买状态
     */
	public static final String mycaibo_buy_orderstatus = BASE_IP+"caibao_my/buycoin/";
	
	/**
     * 更新购买状态
     */
	public static final String mycaibo_buy_status = BASE_IP+"caibao_my/buycoin/";
	
	
	/*************其他模块的************/
	
	/**
	 * 版本升级
	 */
	public static final String update=BASE_IP+"caibao_my/version/";
	
	/**
	 * 公告检测
	 */
	public static final String notice_check=BASE_IP+"caibao_my/notice/";
	/**
	 * 获取验证码
	 */
	public static final String vercode_get=BASE_IP+"caibao_my/forget/";
	
	/**
	 * 检测验证码
	 */
	public static final String vercode_check=BASE_IP+"caibao_my/forget/";
	/**
	 * 设置密码
	 */
	public static final String pwd_set=BASE_IP+"caibao_my/forget/";
	/**
	 * 	意见反馈
	 */
	public static final String feedback=BASE_IP+"caibao_my/feedback/";
	
	/**
	 *彩宝攻略
	 */
	public static final String caibo_gonglue=BASE_IP+"caibao_my/qa/";
	/**
	 * 关于我们
	 */
	public static final String about_us=BASE_IP+"caibao_my/aboutus/";
	/**
	 * 发送手机唯一串
	 */
	public static final String deviceid_send=BASE_IP+"caibao_my/deviceId/";
	/**
	 * 获取说明
	 */
	public static final String instruction=BASE_IP+"caibao_my/instruction/";
	/**
	 * 	6.4.登录
	 */
	public static final String mylogin=BASE_IP+"caibao_my/login/";
	/**
	 * 注册
	 */
	public static final String regist = BASE_IP+"caibao_my/register/";
	
	/***************************** 常量开始 *******************************************/
	/**
	 * 返回的数据OK
	 */
	public static final int HTTP_OK = -10;
	/**
	 * 返回数据错误
	 */
	public static final int HTTP_ERROR = -11;
	/**
	 * 网络超时
	 */
	public static final int HTTP_ERROR_NET = -12;
	/**
	 * 返回数据解析错误
	 */
	public static final int HTTP_ERROR_PASER = -13;

	/**
	 * 首页广告
	 */
	public static final int ADVERT_LIST = 10;

	/************** 财宝推荐 ***********************/
	/**
	 * 获取进行中的推荐列表
	 */
	public static final int CAIBO_RMD_RUNNING = 11;
	/**
	 * 获取已完成的推荐列表
	 */
	public static final int CAIBO_RMD_FINISHED = 12;
	/**
	 * 获取推荐方案统计数据
	 */
	public static final int CAIBO_RMD_STATISTICS = 13;
	/**
	 * 获取具体方案内容
	 */
	public static final int CAIBO_RMD_PLAN = 14;
	/**
	 * 获取方案评论内容
	 */
	public static final int CAIBO_RMD_COMMENT_GET = 15;
	/**
	 * 评论方案
	 */
	public static final int CAIBO_RMD_COMMENT_POST = 16;
	/**
	 * 评价方案
	 */
	public static final int CAIBO_RMD_EVLUATIONN = 17;
	/**
	 * 选择彩种
	 */
	public static final int CAIBO_RMD_LOTTERY = 18;

	/**
	 * 获取可订购服务
	 */
	public static final int CAIBO_RMD_ORDER = 19;
	/**
	 * 获取服务价格
	 */
	public static final int CAIBO_RMD_ORDER_PRICE = 20;
	/**
	 * 获取可订购服务
	 */
	public static final int CAIBO_RMD_ORDER_BUY = 21;

	/************** 专家推荐 ***********************/
	/**
	 * 获取进行中的推荐列表
	 */
	public static final int EXPERT_RMD_RUNNING = 22;
	/**
	 * 获取已完成的推荐列表
	 */
	public static final int EXPERT_RMD_FINISHED = 23;
	/**
	 * 获取推荐方案统计数据
	 */
	public static final int EXPERT_RMD_STATISTICS = 24;
	/**
	 * 获取具体方案内容
	 */
	public static final int EXPERT_RMD_PLAN = 25;
	/**
	 * 获取方案评论内容
	 */
	public static final int EXPERT_RMD_COMMENT_GET = 26;
	/**
	 * 评论方案
	 */
	public static final int EXPERT_RMD_COMMENT_POST = 27;
	/**
	 * 评价方案
	 */
	public static final int EXPERT_RMD_EVLUATIONN = 28;
	/**
	 * 选择彩种
	 */
	public static final int EXPERT_RMD_LOTTERY = 29;

	/**
	 * 获取可订购服务
	 */
	public static final int EXPERT_RMD_ORDER = 30;
	/**
	 * 获取服务价格
	 */
	public static final int EXPERT_RMD_ORDER_PRICE = 31;
	/**
	 * 获取可订购服务
	 */
	public static final int EXPERT_RMD_ORDER_BUY = 32;
	/**
	 * 获取专家信息
	 */
	public static final int EXPERT_INFO_GET = 33;

	/*********** 开奖公告 *********************/
	/**
	 * 获取开奖公告list
	 */
	public static final int BULLETIN_LIST = 34;
	/**
	 * 彩种排序
	 */
	public static final int BULLETIN_SHOW = 35;
	/**
	 * 获取开奖公告
	 */
	public static final int BULLETIN_LOTTSORT = 36;
	/**
	 * 开奖号码
	 */
	public static final int BULLETIN_NUMBER = 37;
	
	/****************我的彩宝***********************/
	/**
	 * 用户信息
	 */
	public static final int CAIBO_MY_USER_INFO = 38;
	
	/**
	 * 获取彩宝价格
	 */
	public static final int MY_CAIBO_BUYCOIN = 39;
	/**
	 * 确定购买单号
	 */
	public static final int MYCAIBO_BUY_NO = 40;
    /**
     * 登录
     */
	public static final int LOGIN_FLAG=41;
	
	/**
	 * 基础数据 lastid
	 */
	public static final int HTTP_OK_LASTID = 41;
	/**
	 * 注册
	 */
	public static final int REGIST_FLAG = 42;
	public static double Latitude = 0;
	public static  double Longitude = 0;
	
	

	/**
	 * 版本升级FLAG
	 */
	public static final int UPDATE_FALG=43;
	/**
	 * 公告检测FLAG
	 */
	public static final int NOTICE_CHECK_FLAG=44;
	/**
	 * 获取验证码FLAG
	 */
	public static final int VERCODE_GET=45;
	/**
	 * 检测验证码FLAG
	 */
	public static final int VERCODE_CHECK=46;
	/**
	 * 设置密码FLAG
	 */
	public static final int PWD_SET=47;
	/**
	 * 意见反馈FLAG
	 */
	public static final int FEEDBACK_FLAG=48;
	/**
	 * 彩宝攻略FLAG
	 */
	public static final int CAIBO_GONGLUE=49;
	/**
	 * 关于我们FLAG
	 */
	public static final int ABOUT_US=50;
	/**
	 * 发送手机唯一串FLAG
	 */
	public static final int DEVICEID_SEN=51;
	/**
	 * 发送手机唯一串FLAG
	 */
	public static final int INSTRUCTION_FLAG=52;
	

	/****************************** 常量结束 ******************************************/

	// 序列化userbean到本地
	public static void saveUserBean(UserInfo userbean) {
		SharedPreferences mSharedPreferences = BaseApplication.getInstance()
				.getSharedPreferences("base64", Context.MODE_PRIVATE);
		try {
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			ObjectOutputStream oos = new ObjectOutputStream(baos);
			oos.writeObject(userbean);

			String personBase64 = new String(Base64.encode(baos.toByteArray(),
					Base64.DEFAULT));
			SharedPreferences.Editor editor = mSharedPreferences.edit();
			editor.putString("person", personBase64);
			editor.commit();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static UserInfo getUserBean() {
		try {
			SharedPreferences mSharedPreferences = BaseApplication
					.getInstance().getSharedPreferences("base64",
							Context.MODE_PRIVATE);
			String personBase64 = mSharedPreferences.getString("person", "");
			byte[] base64Bytes = Base64.decode(personBase64, Base64.DEFAULT);// Base64.decodeBase64(personBase64.getBytes(),Base64.DEFAULT);
			ByteArrayInputStream bais = new ByteArrayInputStream(base64Bytes);
			ObjectInputStream ois = new ObjectInputStream(bais);
			UserInfo user = (UserInfo) ois.readObject();

			return user;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}

	}

	/**
	 * @author py 关闭editText
	 */
	public static void closeSoftInput(EditText editText) {

		try {
			InputMethodManager inputManager =

			(InputMethodManager) editText.getContext().getSystemService(
					Context.INPUT_METHOD_SERVICE);

			inputManager.hideSoftInputFromWindow(editText.getWindowToken(), 0);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * @author py editText限制输入字数
	 * @param Context
	 * @param msg
	 *            提示信息
	 * @param num
	 *            限制字数
	 */
	private static long lastClickTime;
	public static String Adress;

	public final static int loginToken = 78;

	public static  final int VERIFACATION = 77;

	public static final int UPLOADFILE = 79;
	
	

	public static boolean isFastDoubleClick(long maxtime) {
		long time = System.currentTimeMillis();
		long timeD = time - lastClickTime;
		if (0 < timeD && timeD < maxtime) {
			Log.i("test", "太快了");
			return true;

		}
		lastClickTime = time;
		return false;
	}

	public static InputFilter[] lengthFilter(final Context context,
			final String msg, final int num) {
		InputFilter[] filters = { new InputFilter.LengthFilter(50) {
			@Override
			public CharSequence filter(CharSequence source, int start, int end,
					Spanned dest, int dstart, int dend) {
				String text = dest.toString() + source.toString();
				try {
					if (text.getBytes("GBK").length > num) {
						if (msg != null) {
							CustomToast.makeText(context, msg, 0);
						}
						return "";
					}
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
				return source;
			}
		} };
		return filters;
	}

	public static boolean ExistSDCard() {
		if (android.os.Environment.getExternalStorageState().equals(
				android.os.Environment.MEDIA_MOUNTED)) {
			return true;
		} else
			return false;
	}

	public static void setImageMargin(View view) {
		RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
				RelativeLayout.LayoutParams.WRAP_CONTENT,
				RelativeLayout.LayoutParams.WRAP_CONTENT);
		layoutParams.setMargins(64, 36, 64, 36);
		view.setLayoutParams(layoutParams);
	}

}
